package everyday;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class T1093 {
    public double[] sampleStats(int[] count) {
        int min = 255;
        int max = 0;
        int mode = 0;
        int modeSum = 0;
        long sum = 0;
        int total = Arrays.stream(count).sum();
        double median = 0;
        int cnt = 0;
        int left = (total + 1) / 2;
        int right = (total + 2) / 2;
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < count.length; i++) {
            if (count[i] > 0) {
                if (i < min) min = i;
                if (i > max) max = i;
                if (count[i] > modeSum) {
                    modeSum = count[i];
                    mode = i;
                }
                if (cnt < left && cnt + count[i] >= left) median += i;
                if (cnt < right && cnt + count[i] >= right) median += i;
                sum += (long) count[i] * i;
                cnt += count[i];
            }
        }
        median = median / 2;
        double mean = (double) sum / total;
        return new double[]{min, max, mean, median, mode};
    }
}
